package com.ict.ms.controller;


import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ict.ms.realTime.facade.api.IStaticInfoService;
import com.ict.ms.realTime.facade.common.StateMsg;
import com.ict.ms.realTime.facade.dto.ResultObj;

import javax.annotation.Resource;

@Controller
@RequestMapping("/static")
public class StaticInfoController {
    @Resource
    IStaticInfoService staticInfoService;

    /**
     * 获取所有国家地区信息
     * @param map
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "getcountry.do",method = RequestMethod.GET)
    public String getcountry(ModelMap map){
        String msg;
        String jsonStr;

        ResultObj resultObj=staticInfoService.getListStaticCountry();
        if (resultObj.getState()==0){
            msg="列表为空";
            map.addAttribute("result",msg);
            jsonStr = StateMsg.toJson(0, map);
        }else if(resultObj.getState()==-1){
            msg="获取列表失败";
            map.addAttribute("result",msg);
            jsonStr = StateMsg.toJson(-1, map);
        }else{
            map.addAttribute("list",resultObj.getObj());
            jsonStr = StateMsg.toJson(1, map);
        }

        return jsonStr;
    }

    /**
     * 获取所有船舶类型列表
     * @param map
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "getshiptype.do",method = RequestMethod.GET)
    public String getshiptype(ModelMap map){
        String msg;
        String jsonStr;

        ResultObj resultObj=staticInfoService.getListStaticShipType();
        if (resultObj.getState()==0){
            msg="列表为空";
            map.addAttribute("result",msg);
            jsonStr = StateMsg.toJson(0, map);
        }else if(resultObj.getState()==-1){
            msg="获取列表失败";
            map.addAttribute("result",msg);
            jsonStr = StateMsg.toJson(-1, map);
        }else{
            map.addAttribute("list",resultObj.getObj());
            jsonStr = StateMsg.toJson(1, map);
        }

        return jsonStr;
    }

    /**
     * 更新船舶档案资料
     * @param map
     * @param shipid 船舶原始id
     * @param shipytpe 船舶类型
     * @param content json格式要更新的字段及值
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "updatecivil.do",method = RequestMethod.POST)
    public String updatecivil(ModelMap map
            , @RequestParam(value = "shipid", required = false) int shipid
            , @RequestParam(value = "shiptype", required = false) int shipytpe
            , @RequestParam(value = "content", required = false) String content) {
        String msg;
        String jsonStr;

        ResultObj resultObj = staticInfoService.updateCivilShipInfo(shipid,shipytpe,content);
        if(resultObj.getState()==-1){
            msg="操作失败";
            map.addAttribute("result",msg);
            jsonStr = StateMsg.toJson(-1, map);
        }else{
            msg="修改成功";
            map.addAttribute("result",msg);
            jsonStr = StateMsg.toJson(1, map);
        }

        return jsonStr;
    }
}
